<?php
class pro_lap_event_model extends MY_Model {
	var $model = 'pro_lap_event_model';

	function GetJSON()
	{
		$ls_sql	= "	SELECT	
					no_event,
					no_surat,
					nama_event,
					jam_kegiatan,
					keterangan,
					jenis_event,
					izin_kepolisian,
					to_char(to_date(tanggal_mulai_kegiatan, 'dd-MON-yy'), 'DD/MM/YYYY') as tanggal_mulai_kegiatan,
					to_char(to_date(tanggal_selesai_kegiatan, 'dd-MON-yy'), 'DD/MM/YYYY') as tanggal_selesai_kegiatan
					FROM	pro_event
					WHERE	(UPPER(no_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_mulai_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_selesai_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jam_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(foto_info_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(izin_kepolisian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_event' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode($this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_event', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_event', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_no_event){
		$result = $this->db->get_where('pro_event', array('no_event' => $as_no_event));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_no_event)
	{
		$result = $this->db->get_where('pro_event', array('no_event' => $as_no_event));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_event WHERE no_event = '".$arr_rule['no_event']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['no_event']."]<br />";
			}else{
				$this->db->delete('pro_event', array('no_event' => $arr_rule['no_event']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>